home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / icons+tools / associate_v1.2 / source / associate.c next >
C/C++ Source or Header  |  1995-12-22  |  17KB  |  712 lines

  1. /* Associate (C) 1995 Dominic Clifton - AKA Hydra/LSD */
  2.  
  3. // note: you MUST have a global define KS20 or KS30 set or CRASH!!!
  4. // I use SCOptions to set it...
  5.  
  6.  
  7. #define MAIN
  8. #include "includes.h"
  9. static UBYTE   *VersTag = "$VER: Associate 1.2 (30.08.95)";
  10. #include "vars.h"
  11. #include <wb2cli.h>
  12.  
  13. char appiconname[]="Associate";
  14. char msgstr[300];
  15. BOOL done=FALSE;
  16. char cfgname[]="S:Associate.cfg";
  17. BOOL All=FALSE;
  18. ULONG doalldrawers=0;
  19.  
  20. /*
  21.    SHITTTTTTTTTTTTTTTTTTTTTT Nodes in a list that point to lists that point to
  22.    more nodes are VERY confusing! :-)
  23. */
  24.  
  25. // next four functions nicked from YAK source code..  ta very much..
  26. // (but they are modified a bit tho..)
  27.  
  28. char __regargs *
  29. TTString(struct DiskObject *diskobj,char *name, char *def)
  30. {
  31.   char *what;
  32.   if (diskobj)
  33.     if (what = FindToolType(diskobj->do_ToolTypes, name))
  34.       return what;
  35.   return def;
  36. }
  37.  
  38. /* like ArgInt() */
  39. LONG __regargs
  40. TTInt(struct DiskObject *diskobj,char *name, LONG def)
  41. {
  42.   char *what;
  43.   if (diskobj)
  44.     if (what = FindToolType(diskobj->do_ToolTypes, name))
  45.       StrToLong(what, &def);
  46.   return def;
  47. }
  48.  
  49. struct Node *GetNode(struct List *lh, UWORD n)
  50. {
  51.   struct Node *ln;
  52.  
  53.   for (ln = lh->lh_Head; n--; ln = ln->ln_Succ)
  54.     ;
  55.   return ln;
  56. }
  57.  
  58. UWORD GetNodeNum(struct List *lh, struct Node *node)
  59. {
  60.   struct Node *ln;
  61.   UWORD i;
  62.  
  63.   for (i = 0, ln = lh->lh_Head; ln != node; ln = ln->ln_Succ, i++)
  64.     ;
  65.   return i;
  66. }
  67.  
  68. //  ok now for the bitchy list stuff..
  69.  
  70. void FreeNameList(struct List *FileList)
  71. {
  72.   struct Node *Current,*Next;
  73.  
  74.   if (Current=FileList->lh_Head)
  75.   {
  76.     while (FileList->lh_Head->ln_Succ)
  77.     {
  78.       Next=Current->ln_Succ;
  79.       if (Current->ln_Name)
  80.       {
  81.         free(Current->ln_Name);
  82.       }
  83.       Remove(Current);
  84.       FreeMem(Current,sizeof(struct Node));
  85.       Current=Next;
  86.     }
  87.   }
  88. }
  89.  
  90. struct Node *NewNameNode(struct List *NameList,char *str)
  91. {
  92.   struct Node *new=NULL;
  93.  
  94.   if (new=AllocMem(sizeof(struct Node),MEMF_PUBLIC))
  95.   {
  96.     new->ln_Name=strdup(str);
  97.     AddTail(NameList,new);
  98.   }
  99.   return(new);
  100. }
  101.  
  102. void FreeNameNode(struct Node *node)
  103. {
  104.   if (node->ln_Name)
  105.   {
  106.     free(node->ln_Name);
  107.   }
  108. }
  109.  
  110.  
  111. void FreeTypeNode(struct TypeNode *new)
  112. {
  113.   if (new->nameplist)
  114.   {
  115.     FreeNameList(new->nameplist);
  116.     FreeMem(new->nameplist,sizeof (struct List));
  117.   }
  118.   if (new->fileplist)
  119.   {
  120.     FreeNameList(new->fileplist);
  121.     FreeMem(new->fileplist,sizeof (struct List));
  122.   }
  123.   if (new->IconName) free(new->IconName);
  124.   FreeNameNode(&new->typenode);
  125. }
  126.  
  127. void FreeTypeList(struct List *TypeList)
  128. {
  129.   struct TypeNode *Current,*Next;
  130.  
  131.   if (Current=(struct TypeNode*)TypeList->lh_Head)
  132.   {
  133.     while (TypeList->lh_Head->ln_Succ)
  134.     {
  135.       Next=(struct TypeNode *)Current->typenode.ln_Succ;
  136.       FreeTypeNode(Current);
  137.       Remove((struct Node*) Current);
  138.       FreeMem(Current,sizeof(struct TypeNode));
  139.       Current=Next;
  140.     }
  141.   }
  142. }
  143.  
  144.  
  145. short AllocTypeNode(struct TypeNode *new)
  146. {
  147.   short retval=FALSE;
  148.   if (new->nameplist=AllocMem(sizeof(struct List),MEMF_ANY))
  149.   {
  150.     NewList(new->nameplist);
  151.     if (new->fileplist=AllocMem(sizeof(struct List),MEMF_ANY))
  152.     {
  153.       NewList(new->fileplist);
  154.       if (new->IconName=malloc(256))
  155.       {
  156.         new->IconName[0]='\0';
  157.         retval=TRUE;
  158.       }
  159.     }
  160.   }
  161.   return (retval);
  162. }
  163.  
  164. struct TypeNode *NewTypeNode(struct List *TypeList,char *str)
  165. {
  166.   struct TypeNode *new=NULL;
  167.  
  168.   if (new=AllocMem(sizeof(struct TypeNode),MEMF_PUBLIC))
  169.   {
  170.  
  171.     new->typenode.ln_Name=strdup(str); // I should REALLY error check this line.
  172.     new->nameplist=NULL; // initialize structure..
  173.     new->fileplist=NULL;
  174.     new->IconName=NULL;
  175.     new->RunInfo=0;
  176.  
  177.     if (AllocTypeNode(new))
  178.     {
  179.       AddTail(TypeList,(struct Node *)new);
  180.     }
  181.     else
  182.     {
  183.       FreeTypeNode(new);
  184.       FreeMem(new,sizeof(struct TypeNode));
  185.       new=NULL;
  186.     }
  187.   }
  188.   return(new); // return NULL for fail or the pointer to the new structure..
  189. }
  190.  
  191. void SetDefault( void )
  192. {
  193.   struct TypeNode *mytn;
  194.   struct Node *mynode;
  195.   struct List *namelist;
  196.  
  197.   mytn=NewTypeNode(typelist,"Picture");
  198.   if (mytn)
  199.   {
  200.     mytn->IconName="ENV:Sys/Def_Misc.info";
  201.     namelist=mytn->nameplist;
  202.     mynode=NewNameNode(namelist,"#?.PIC");
  203.     mynode=NewNameNode(namelist,"#?.GIF");
  204.     mynode=NewNameNode(namelist,"#?.JPG");
  205.     mynode=NewNameNode(namelist,"#?.JPEG");
  206.     mynode=NewNameNode(namelist,"#?.IFF");
  207.     mynode=NewNameNode(namelist,"#?.ILBM");
  208.     namelist=mytn->fileplist;
  209.     mynode=NewNameNode(namelist,"FORM????ILBM#?");
  210.     mynode=NewNameNode(namelist,"GIF#?");
  211.   }
  212.   mytn=NewTypeNode(typelist,"Source Code");
  213.   if (mytn)
  214.   {
  215.     mytn->IconName="ENV:Sys/def_Source.info";
  216.     namelist=mytn->nameplist;
  217.     mynode=NewNameNode(namelist,"#?.c");
  218.     mynode=NewNameNode(namelist,"#?.s");
  219.     mynode=NewNameNode(namelist,"#?.i");
  220.     mynode=NewNameNode(namelist,"#?.h");
  221.     mynode=NewNameNode(namelist,"#?.p");
  222.     mynode=NewNameNode(namelist,"#?.pas");
  223.   }
  224. }
  225.  
  226. short SetUp( void )
  227. {
  228.   short retval=FALSE;
  229.  
  230.   if (ReqToolsBase = (struct ReqToolsBase *) OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION))
  231.   {
  232.     if (typelist=AllocMem(sizeof(struct List),MEMF_ANY))
  233.     {
  234.       NewList(typelist);
  235.       if(IconBase = OpenLibrary("icon.library",37))
  236.       {
  237. #ifdef KS20
  238.         if (WorkbenchBase=OpenLibrary("workbench.library",37))
  239. #endif
  240. #ifdef KS30
  241.         if (WorkbenchBase=OpenLibrary("workbench.library",39))
  242. #endif
  243.         {
  244.           if (ascport=CreateMsgPort())
  245.           {
  246.             if (filereq = rtAllocRequestA (RT_FILEREQ, NULL))
  247.             {
  248.               retval=TRUE;
  249.             }
  250.             else rtEZRequest("Could not allocate requester",okstr,NULL,NULL);
  251.           }
  252.           else rtEZRequest("Could Not Create Message Port!",okstr,NULL,NULL);
  253.         }
  254. #ifdef KS20
  255.         else rtEZRequest("You Need workbench.library v37+!",okstr,NULL,NULL);
  256. #endif
  257. #ifdef KS30
  258.         else rtEZRequest("You Need workbench.library v39+!",okstr,NULL,NULL);
  259. #endif
  260.       }
  261.       else rtEZRequest("You Need icon.library v37!",okstr,NULL,NULL);
  262.     }
  263.     else rtEZRequest("Unable to alloc memory!",okstr,NULL,NULL);
  264.   }
  265.   return(retval);
  266. }
  267.  
  268. void KillAppIcon( void )
  269. {
  270.   if (appicon) RemoveAppIcon(appicon);
  271.   if (ascport)
  272.   {
  273.     while(appmsg=(struct AppMessage *)GetMsg(ascport))
  274.         ReplyMsg((struct Message *)appmsg);
  275.   }
  276. }
  277.  
  278. void CleanUp( void )
  279. {
  280.   KillAppIcon();
  281.   if ( ascport       ) DeleteMsgPort(ascport);
  282.   if ( dobj          ) FreeDiskObject(dobj);
  283.   if ( WorkbenchBase ) CloseLibrary(WorkbenchBase);
  284.   if ( IconBase      ) CloseLibrary(IconBase);
  285.   if ( filereq       ) rtFreeRequest (filereq);
  286.   if ( ReqToolsBase  ) CloseLibrary ((struct Library *)ReqToolsBase);
  287.   if ( typelist      )
  288.   {
  289.     FreeTypeList(typelist);
  290.     FreeMem(typelist,sizeof(struct List));
  291.   }
  292. }
  293.  
  294. short OpenAppIcon( void )
  295. {
  296.   short retval=FALSE;
  297.   if ((dobj=GetDiskObject(appiconname))==NULL)
  298.   {
  299.     sprintf(msgstr,"Could Not Open %s.info",appiconname);
  300.     rtEZRequest(msgstr,okstr,NULL,NULL);
  301.   }
  302.   else
  303.   {
  304.     dobj->do_Type=NULL; // set to null for appicon..,
  305.     // temp fix until loadprefs has been written..
  306.     dobj->do_CurrentX=TTInt(dobj,"ICONX",NO_ICON_POSITION);
  307.     dobj->do_CurrentY=TTInt(dobj,"ICONY",NO_ICON_POSITION);
  308.     // wb don't like only one of the coords set.. :-)
  309.     if (dobj->do_CurrentX >= 0 && dobj->do_CurrentY == NO_ICON_POSITION) dobj->do_CurrentY=1;
  310.     if (dobj->do_CurrentY >= 0 && dobj->do_CurrentX == NO_ICON_POSITION) dobj->do_CurrentX=1;
  311.     if ((appicon=AddAppIconA(0L,0L,appiconname,ascport,NULL,dobj,NULL))==NULL)
  312.     {
  313.       rtEZRequest("Could Not Create App Icon!",okstr,NULL,NULL);
  314.     }
  315.     else
  316.     {
  317.       retval=TRUE;
  318.     }
  319.   }
  320.   return(retval);
  321. }
  322.  
  323. void DoOptions( void )
  324. {
  325.   if (!OpenAssociateWindow())
  326.   {
  327. #ifdef KS20
  328.     LastTypeClicked=-1;
  329. #endif
  330.     GT_SetGadgetAttrs(AssociateGadgets[GD_TypeList], AssociateWnd, NULL,
  331.                       GTLV_Labels, (ULONG)typelist,
  332.                       GTLV_Selected,0,
  333.                       TAG_END);
  334.     UpdateLists();
  335.     do
  336.     {
  337.       Wait (1 << AssociateWnd->UserPort->mp_SigBit);
  338.     } while (HandleAssociateIDCMP());
  339.     CloseAssociateWindow();
  340.   }
  341. }
  342.  
  343. void CreateIcon(char *filename, struct TypeNode *tnode)
  344. {
  345.   char *iconname;
  346.   struct DiskObject *icn;
  347.  
  348.   iconname=strdup(tnode->IconName);
  349.   removeinfo(iconname);
  350.   if (icn=GetDiskObject(iconname))
  351.   {
  352.     icn->do_CurrentX=NO_ICON_POSITION;
  353.     icn->do_CurrentY=NO_ICON_POSITION;
  354.     PutDiskObject(filename,icn);
  355.     FreeDiskObject(icn);
  356.   }
  357.   if (tnode->RunInfo)
  358.   {
  359.     DoInfo(filename);
  360.   }
  361.   free(iconname);
  362. }
  363.  
  364. void PickType(char *filename)
  365. {
  366.   if (!OpenPickWindow())
  367.   {
  368. #ifdef KS20
  369.     LastPickClicked=-1;
  370. #endif
  371.     GT_SetGadgetAttrs(PickGadgets[GD_PickType], PickWnd, NULL,
  372.                       GTLV_Labels, (ULONG)typelist,
  373.                       GTLV_Selected,0,
  374.                       TAG_END);
  375.     do
  376.     {
  377.       Wait (1 << PickWnd->UserPort->mp_SigBit);
  378.     } while (HandlePickIDCMP());
  379.  
  380.     // this is the only place temptnode is relied on between functions..
  381.     // so be carefull
  382.  
  383.     if (temptnode) // idcmp handling will set this to NULL if pickwindow is cancelled
  384.     {
  385.       CreateIcon(filename,temptnode);
  386.     }
  387.     ClosePickWindow();
  388.   }
  389. }
  390.  
  391. BOOL MatchFile(char *matchpattern, char *filename)
  392. {
  393.   BPTR File;
  394.   char *buffer;
  395.   LONG buflen;
  396.   BOOL retval=FALSE;
  397.   char match[256];
  398.   short loop;
  399.  
  400.   if (buffer=malloc(21))
  401.   {
  402.     if (File=Open(filename,MODE_OLDFILE))
  403.     {
  404.       if (buflen=Read(File,buffer,20)) // read 1st 20 bytes
  405.       {
  406.         for (loop=0;loop<buflen;loop++) // and check..
  407.         {
  408.           if (buffer[loop]==0) buffer[loop]='.'; // replace null bytes with .'s..
  409.         }
  410.         ParsePatternNoCase(matchpattern,match,255);
  411.         if (MatchPatternNoCase(match,buffer))
  412.         {
  413.           retval=TRUE;
  414.         }
  415.       }
  416.       Close(File);
  417.     }
  418.     free(buffer);
  419.   }
  420.   return(retval);
  421. }
  422.  
  423. LONG MatchOK(char *filename,struct TypeNode *tnode)
  424. {
  425.   LONG result;
  426.  
  427.   if (!All)
  428.   {
  429.     sprintf(msgstr,"Matched file \"%s\" against\n"
  430.                    "type \"%s\"\n"
  431.                    "Do you want to use this type\n"
  432.                    "or continue searching ?",FilePart(filename),tnode->typenode.ln_Name);
  433.     result=rtEZRequestTags(msgstr,"OK!|All|Continue..",NULL,NULL,RTGS_Flags,GSREQF_CENTERTEXT,TAG_END);
  434.     if (result==2) All=TRUE;
  435.     return(result);
  436.   }
  437.   else return(1);
  438. }
  439.  
  440. void DoIcon( char *filename)
  441. {
  442.   struct TypeNode *tnode;
  443.   struct Node *node;
  444.   char match[256];
  445.   char temp;
  446.   LONG Matched=FALSE;
  447.   char *iconname;
  448.   struct DiskObject *icn;
  449.  
  450.   temp=filename[strlen(filename)-1];
  451.   if (temp!='/' && temp!=':')
  452.   {
  453.     for (tnode = (struct TypeNode *) typelist->lh_Head ; !Matched && tnode->typenode.ln_Succ ; tnode = (struct TypeNode *)tnode->typenode.ln_Succ)
  454.     {
  455.       for (node = tnode->nameplist->lh_Head ; !Matched && node->ln_Succ ; node = node->ln_Succ)
  456.       {
  457.         ParsePatternNoCase(node->ln_Name,match,255);
  458.         if (MatchPatternNoCase(match,FilePart(filename)))
  459.         {
  460.           Matched=MatchOK(filename,tnode);
  461.         }
  462.       }
  463.       for (node = tnode->fileplist->lh_Head ; !Matched && node->ln_Succ ; node = node->ln_Succ)
  464.       {
  465.         // printf("File Checking %s\n",node->ln_Name);
  466.         if (MatchFile(node->ln_Name,filename))
  467.         {
  468.           Matched=MatchOK(filename,tnode);
  469.         }
  470.       }
  471.       if (Matched)
  472.       {
  473.         CreateIcon(filename,tnode);
  474.       }
  475.     }
  476.     if (!Matched)
  477.     {
  478.       sprintf(msgstr,"Sorry, I could not find a match\n"
  479.                      "for the file \"%s\"",FilePart(filename));
  480.       if (rtEZRequestTags(msgstr,"Select A Type|Skip",NULL,NULL,RTGS_Flags,GSREQF_CENTERTEXT,TAG_END))
  481.       {
  482.         PickType(filename);
  483.       }
  484.     }
  485.   }
  486.   else
  487.   {
  488.     if (iconname=strdup(filename))
  489.     {
  490.       sprintf(msgstr,"Copy Default %s Icon \nto %s ?",temp == '/' ? "Drawer" : "Disk",iconname);
  491.       if (temp=='/')
  492.       {
  493.  
  494.         if ((doalldrawers==2) || (doalldrawers=rtEZRequest(msgstr,"Yes|All|Cancel",NULL,NULL)))
  495.         {
  496.           iconname[strlen(iconname)-1]=0;
  497.           if (icn=GetDiskObject("env:sys/def_drawer"))
  498.           {
  499.             icn->do_CurrentX=NO_ICON_POSITION;
  500.             icn->do_CurrentY=NO_ICON_POSITION;
  501.             PutDiskObject(iconname,icn);
  502.             FreeDiskObject(icn);
  503.           }
  504.         }
  505.       }
  506.       else // disk..
  507.       {
  508.         if (rtEZRequest(msgstr,"Yes|Cancel",NULL,NULL))
  509.         {
  510.           strcat(iconname,"disk");
  511.           if (icn=GetDiskObject("env:sys/def_disk"))
  512.           {
  513.             icn->do_CurrentX=NO_ICON_POSITION;
  514.             icn->do_CurrentY=NO_ICON_POSITION;
  515.             PutDiskObject(iconname,icn);
  516.             FreeDiskObject(icn);
  517.           }
  518.         }
  519.       }
  520.       free(iconname);
  521.     }
  522.   }
  523. }
  524.  
  525. void CheckMessages( void )
  526. {
  527.   short loop;
  528.   char *filename;
  529.  
  530.   All=FALSE;
  531.   doalldrawers=0;
  532.   while(appmsg=(struct AppMessage *)GetMsg(ascport))
  533.   {
  534.     if(appmsg->am_NumArgs==0L)
  535.     {
  536.       DoOptions();
  537.     }
  538.     else if(appmsg->am_NumArgs>0L)
  539.     {
  540.       if (filename=malloc(256))
  541.       {
  542.         for(loop=0;loop<appmsg->am_NumArgs;loop++)
  543.         {
  544.           NameFromLock(appmsg->am_ArgList[loop].wa_Lock,filename,255);
  545.           AddPart(filename,appmsg->am_ArgList[loop].wa_Name,255);
  546.           DoIcon(filename);
  547.         }
  548.         free(filename);
  549.       }
  550.     }
  551.     ReplyMsg((struct Message *)appmsg);
  552.   }
  553. }
  554.  
  555. void stripcr( char *str)
  556. {
  557.   if (str[strlen(str)-1]=='\n') str[strlen(str)-1]=0;
  558.   if (str[strlen(str)-1]=='\r') str[strlen(str)-1]=0;
  559. }
  560.  
  561. void SavePrefs( void )
  562. {
  563.   FILE *File;
  564.   struct TypeNode *tnode;
  565.   struct Node *node;
  566.  
  567.   if (File=fopen(cfgname,"w"))
  568.   {
  569.     for (tnode = (struct TypeNode *) typelist->lh_Head ;tnode->typenode.ln_Succ ; tnode = (struct TypeNode *)tnode->typenode.ln_Succ)
  570.     {
  571.       fprintf(File,"|STARTLIST\n"
  572.                    "%s\n" // node name
  573.                    "%s\n" // icon name
  574.                    "%d\n", // RunInfo
  575.                    tnode->typenode.ln_Name,tnode->IconName,tnode->RunInfo);
  576.       if (tnode->nameplist->lh_Head->ln_Succ)
  577.       {
  578.         fprintf(File,"|NAMEPATTERN\n");
  579.         for (node = tnode->nameplist->lh_Head ;node->ln_Succ ; node = node->ln_Succ)
  580.         {
  581.           fprintf(File,"%s\n",node->ln_Name);
  582.         }
  583.       }
  584.       if (tnode->fileplist->lh_Head->ln_Succ)
  585.       {
  586.         fprintf(File,"|FILEPATTERN\n");
  587.         for (node = tnode->fileplist->lh_Head ;node->ln_Succ ; node = node->ln_Succ)
  588.         {
  589.           fprintf(File,"%s\n",node->ln_Name);
  590.         }
  591.       }
  592.       fprintf(File,"|ENDLIST\n");
  593.     }
  594.     fclose(File);
  595.   }
  596. }
  597.  
  598. short LoadPrefs( void )
  599. {
  600.   FILE *File;
  601.   char str[256];
  602.   char what='x';
  603.  
  604.   // load prefs.  return 1 if OK 0 otherwise..
  605.  
  606.   if (File=fopen(cfgname,"r"))
  607.   {
  608.     while (!feof(File))
  609.     {
  610.       fgets(str,255,File);
  611.       if (!feof(File))
  612.       {
  613.         stripcr(str);
  614.  
  615.         // ok, so i could use a "flag" here :-) buy hey! what do i care..
  616.  
  617.         if (stricmp(str,"|ENDLIST")==0)
  618.         {
  619.           what='x';
  620.         }
  621.         else
  622.         {
  623.           if (stricmp(str,"|NAMEPATTERN")==0)
  624.           {
  625.             what='n';
  626.           }
  627.           else
  628.           {
  629.             if (stricmp(str,"|FILEPATTERN")==0)
  630.             {
  631.               what='f';
  632.             }
  633.             else
  634.             {
  635.               if (stricmp(str,"|STARTLIST")==0)
  636.               {
  637.                 what='l';
  638.               }
  639.               else
  640.               {
  641.                 if (what!='x')
  642.                 {
  643.                   switch(what)
  644.                   {
  645.                     case 'n':
  646.                       NewNameNode(temptnode->nameplist,str);
  647.                       break;
  648.                     case 'f':
  649.                       NewNameNode(temptnode->fileplist,str);
  650.                       break;
  651.                     case 'r':
  652.                       sscanf(str,"%d",&temptnode->RunInfo);
  653.                       what='x';
  654.                       break;
  655.                     case 'i':
  656.                       strncpy(temptnode->IconName,str,255); // limited..
  657.                       what='r';
  658.                       break;
  659.                     case 'l':
  660.                       temptnode=NewTypeNode(typelist,str);
  661.                       what='i';
  662.                       break;
  663.                   }
  664.                 }
  665.               }
  666.             }
  667.           }
  668.         }
  669.       }
  670.     }
  671.     fclose(File);
  672.     return(1);
  673.   }
  674.   return(0);
  675. }
  676.  
  677. void main(int argc,char *argv[])
  678. {
  679.   WB2CLI((struct WBStartup *)argv,4000,DOSBase);  /* so you get the default path! */
  680.   SetUp();
  681.   if (!SetupScreen())
  682.   {
  683.     if (!LoadPrefs())
  684.     {
  685.       SetDefault();
  686.       DoOptions();
  687.     }
  688.  
  689.     if (argc==2)
  690.     {
  691.       DoIcon(argv[1]);
  692.     }
  693.     else
  694.     {
  695.       if (OpenAppIcon())
  696.       {
  697.         while (!done)
  698.         {
  699.           WaitPort(ascport);
  700.           CheckMessages();
  701.         }
  702.       }
  703.       else
  704.       {
  705.         rtEZRequest("Could not create an AppIcon!","Quit!",NULL,NULL);
  706.       }
  707.     }
  708.     CloseDownScreen();
  709.   }
  710.   CleanUp();
  711. }
  712.